import requests
import re
import  chardet
import os
import  time



def myMovie(i):
    url = "http://www.dytt8.net/html/gndy/dyzz/list_23_"+str(i)+".html"
    response = requests.get(url)
    response.encoding='gb2312'
    html = response.text
    
    reg = re.compile(r'<b>.*?<a href="(.*?)" class="ulink">(.*?)</a>.*?</b>',re.S)
    movie = re.findall(reg,html)
    for m in movie:

        #time.sleep(2)       #加时间
        url = "http://www.dytt8.net" + m[0]
        response = requests.get(url)
        response.encoding = 'gb2312'
        #print(response.status_code)
        html = response.text
        ftp = re.compile(r'<a href="(.*?)">.*?</a></td>')
        movie = re.findall(ftp,html)
        print(movie)

        # 写入文本
        try:
           with open(r'DYtt.txt','a',encoding='utf-8') as f:
               f.write(movie[0]+'\n')
        except:
            print("这一页没有匹配到")


def main():
    for i in range(1,8):
       myMovie(i)


main()